﻿define(function (require) {
    var utility = require('ezdesk/utility/utility.js');

    return Backbone.View.extend({
        //... is a list tag.
        tagName: "li",
        template: _.template($("#div_workitem").html()),
        events: {
            "click .command": "onCommand"
        },
        initialize: function () {
            var $self = this;
            $(this.el).attr('data-theme', 'c')
                      .addClass('ui-btn ui-btn-icon-right ui-li ui-btn-up-c');

            _.bindAll(this, 'render');
            this.model.bind('change', this.render);
            this.model.view = this;

        },
        render: function () {
            var element = $(this.el)[0];
            $(element).data('cid', this.model.cid);

            $(this.el).html(this.template(this.model.toJSON()));
           
            $(this.el).find('a.ezlink').each(function (index, item) {
                utility.HandleATag(item);
            });

            return this;
        },
        remove: function () {
            $(this.el).remove();
        },

        // Remove the item, destroy the model.
        clear: function () {

        },
        onCommand: function () {
            $(this.el).find('.command').hide();
            $(this.el).find('.img-ajax').show();

            this.model.command();
        }
    });
});